import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Menu } from './Menu';

@Entity()
export class Goods {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 50 })
  name: string;

  @Column({ nullable: true, type: 'longtext' })
  img: string;

  @Column({ nullable: true })
  description: string;

  @Column({ default: 0 })
  price: number;

  @Column({ default: 0 })
  sale: number;

  //对应Person实体中的@OneToMany修饰的字段（不可以单独存在）
  @ManyToOne(() => Menu, (menu) => menu.goods)
  //指定本表中的外键（JoinColumn只存在于多端，因为外键只会存在于多端）
  @JoinColumn({ name: 'menu_id' })
  menu: Menu;

  @CreateDateColumn()
  created: Date;

  @UpdateDateColumn()
  updated: Date;
}
